Starts the whole game over, as if you had just switched the console on. Everything in the game's memory is thrown away, but what you saved with save_commit is kept.
game_restart()Nothing.
Starts the whole game over, as if you had just switched the console off and on again. The Game Boy logo is skipped, and the game begins again in the room it starts in.
This is the big one. room_restart starts only the room you are in again and keeps everything else. game_restart starts everything again.
if (btn_pressed(BTN_START)) {
game_restart();
}Press START and the game starts from the beginning. This is the whole of a "play again" button.
save_set("best_score", 120);
save_commit();
game_restart();Save first, then start over. The best score is still there after the restart, because it was written to the cartridge with save_commit before the game started again.
Your saved game is kept. Everything you wrote with save_commit stays on the cartridge, and the game reads it again when it starts, the same as after the console is switched on. game_restart never clears it. A value you set with save_set but did not commit is not saved yet. It lives in the game's memory, so it is thrown away with the rest.
| Kept | Thrown away |
|---|---|
Everything you wrote with save_commit | Every instance of every object |
Every variable, including the global. ones | |
| The room you were in (the room the game starts in loads again) | |
| A pause, so the game is not paused any more | |
| The music, the camera and every effect | |
A save_set value you never committed |
game_frame starts again from 0.
game_restart does not wait for the end of the frame. The restart happens the moment the line runs:
So put anything you still need, like a save_commit, before the call, not after it.
// This line runs. Then the game restarts and the next line never does.
game_restart();
x += 1;If the very first thing a game does is call game_restart, the game restarts, runs the same line again and restarts again, for ever. Put the call behind an if that checks for something the player did, like a button press, or for something that is different after the restart (a saved value you change before you call it).
A game that never calls game_restart pays nothing for it. A game that does call it needs a little extra code: about 56 bytes in a development build and about 960 bytes in a --release build, measured on a small game.
It happens right away, in the middle of whatever event called it: the lines after it do not run, and no other object gets another turn this frame. Thrown away: every instance, every variable, the room you were in (the room the game starts in loads again), a pause, the music, and any save_set value you never made permanent with save_commit. Kept: everything save_commit has already written to the cartridge. game_frame() starts from 0 again. If the very first thing your game does is call this, it restarts forever.